from typing import Generic, TypeVar, Optional

from pydantic.generics import GenericModel

T = TypeVar("T")


class Rs(GenericModel, Generic[T]):
    # 代号
    code: int = 0

    # 提示消息
    message: str = "OK"

    # 数据
    data: Optional[T] = None

    def ok(self, data: Optional[T] = None) -> "Rs":
        self.data = data
        return self
